package com.monitor.service.impl;

import java.io.File;

import org.apache.struts2.ServletActionContext;

import com.monitor.dao.CallLogDao;
import com.monitor.po.CallLog;
import com.monitor.service.CallLogService;
import com.monitor.util.CommenUtil;
import com.monitor.util.FileUtil;
import com.monitor.util.Pager;

public class CallLogServiceImpl implements CallLogService {
	private CallLogDao callLogDao;

	@Override
	public Pager<CallLog> getCallLogByUid(long uid, int pageSize, int currentPage) throws Exception {
		return callLogDao.getCallLogByUid(uid, pageSize, currentPage);
	}

	@Override
	public boolean deleteCalllog(long uid, long calllogId) throws Exception {
		CallLog log = callLogDao.getCalllogById(calllogId);
		if (log != null && uid == log.getOwnerUid()) {
			callLogDao.deleteCalllog(log);
			String firPath = ServletActionContext.getServletContext().getRealPath("") + "\\" + log.getPath().replace("/", "\\");
			// 删除用户文件目录
			FileUtil.deleteFile(new File(firPath));
			return true;
		} else {
			return false;
		}
	}

	@Override
	public boolean deleteCalllog(long uid, String idStr) throws Exception {
		if (CommenUtil.isEmpty(idStr)) {
			return false;
		}
		String[] arr = idStr.split(",");
		for (String sid : arr) {
			long id = Long.valueOf(sid);
			deleteCalllog(uid, id);
		}
		return true;
	}

	public CallLogDao getCallLogDao() {
		return callLogDao;
	}

	public void setCallLogDao(CallLogDao callLogDao) {
		this.callLogDao = callLogDao;
	}

}
